package org.ainlolcat.ainscience2.controller.utils;

import org.ainlolcat.ainscience2.model.Project;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: ain
 * Date: 17.06.12
 * Time: 16:01
 * To change this template use File | Settings | File Templates.
 */
public class MacrosApplier {
    public String applyMacros(String template, Project project, Map<String,String> custom){
        String result = template;
        if (custom!=null){
            for (String key : custom.keySet()){
                result = result.replaceAll("\\$" + key + "\\$", custom.get(key));
            }
        }

        if (project!=null && project.getMacroses()!=null){
            for (String key : project.getMacroses().keySet()){
                result = result.replaceAll("\\$" + key + "\\$", project.getMacroses().get(key));
            }
        }
        return result;
    }
}
